def longestCommonPrefix(str_list):
    res = str_list[0]
    for s in str_list:
        i = 0
        while i < min(len(s), len(res)) and res[i] == s[i]:
            i += 1
        res = s[:i]
    return res


print(longestCommonPrefix(["flower", "flow", "flight"]))  # fl
print(longestCommonPrefix(["dog", "racecar", "car"]))  # ''
print(longestCommonPrefix(["ab", "a"]))  # a
print(longestCommonPrefix(["reflower", "flow", "flight"]))  # ''
